package com.zhuiyun.pm.client.action.mapper;

import com.zhuiyun.pm.client.action.entity.GoodsEntity;
import com.zhuiyun.pm.config.BaseMapper;
import com.zhuiyun.pm.page.PageRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName GoodsMapper
 * @Description TODO
 * @Author 赵笛
 * @Date 2023/3/14 14:14
 **/

public interface GoodsMapper extends BaseMapper<GoodsEntity> {

    /**
     * @Author 赵笛
     * @Description TODO 查询竞品列表
     * @Date 2023/3/29 19:15
     * @Return java.util.List<com.zhuiyun.pm.client.action.entity.GoodsEntity>
     * @param sellerId
     * @param checkStatus
     * @param goodsName
     */
    @Select("<script>select * from client_goods_info " +
        "where del_flag = 0 " +
        "and check_status = 5 "+
        "<when test = 'goodsName !=&quot; &quot; and goodsName !=null'>" +
        "and goods_name like(concat('%',#{goodsName},'%')) " +
        "</when>" +
        "<when test = 'address !=&quot; &quot; and address !=null'>" +
        "and transaction_address like(concat('%',#{address},'%')) " +
        "</when>" +
        "<when test = 'status !=0 and status !=null'>" +
        "and transaction_status = #{status} " +
        "</when>" +
        "order by start_time desc" +
        "</script>")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "goodsName",column = "goods_name"),
            @Result(property = "goodsNumber",column = "goods_number"),
            @Result(property = "startPrice",column = "start_price"),
            @Result(property = "transactionAddress",column = "transaction_address"),
            @Result(property = "weight",column = "weight"),
            @Result(property = "number",column = "number"),
            @Result(property = "transactionType",column = "transaction_type"),
            @Result(property = "earnestMoney",column = "earnest_money"),
            @Result(property = "transactionType",column = "transaction_type"),
            @Result(property = "imgId",column = "img_id"),
            @Result(property = "transactionStatus",column = "transaction_status"),
            @Result(property = "startTime",column = "start_time"),
            @Result(property = "endTime",column = "end_time"),
            @Result(property = "delayMinutes",column = "delay_minutes"),
            @Result(property = "sellerId",column = "seller_id"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "delayMinutes",column = "delay_minutes"),
            @Result(property = "contactName",column = "contact_name"),
            @Result(property = "imgViewId",column = "img_view_id"),
            @Result(property = "checkStatus",column = "check_status"),
            @Result(property = "delayMinutes",column = "delay_minutes"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "updateTime",column = "update_time"),
            @Result(property = "back",column = "back"),
            @Result(property = "delFlag",column = "del_flag"),
    })

    List<GoodsEntity> getGoodsList(@Param("goodsName")String goodsName,@Param("address")String address,@Param("status") String status,@Param("pageRequest")  PageRequest pageRequest);

    /**
    * @Author 赵笛
    * @Description TODO TODO 根据当前登录用户（卖家）和审核状态查询竞品列表
    * @Date 2023/3/29 19:15
    * @Return java.util.List<com.zhuiyun.pm.client.action.entity.GoodsEntity>
    * @param sellerId
    * @param checkStatus
    * @param goodsName
    */
    
    @Select("<script>select * from client_goods_info " +
            "where del_flag = 0 " +
            "and seller_id = #{sellerId} "+
            "<when test = 'goodsName !=&quot; &quot; and goodsName !=null'>" +
            "and goods_name like(concat('%',#{goodsName},'%')) " +
            "</when>" +
            "<when test = 'checkStatus !=0 and checkStatus !=null'>" +
            "and check_status = #{checkStatus} " +
            "</when>" +
            "order by start_time desc" +
            "</script>")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "goodsName",column = "goods_name"),
            @Result(property = "goodsNumber",column = "goods_number"),
            @Result(property = "startPrice",column = "start_price"),
            @Result(property = "transactionAddress",column = "transaction_address"),
            @Result(property = "weight",column = "weight"),
            @Result(property = "number",column = "number"),
            @Result(property = "transactionType",column = "transaction_type"),
            @Result(property = "earnestMoney",column = "earnest_money"),
            @Result(property = "transactionType",column = "transaction_type"),
            @Result(property = "imgId",column = "img_id"),
            @Result(property = "transactionStatus",column = "transaction_status"),
            @Result(property = "startTime",column = "start_time"),
            @Result(property = "endTime",column = "end_time"),
            @Result(property = "delayMinutes",column = "delay_minutes"),
            @Result(property = "sellerId",column = "seller_id"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "delayMinutes",column = "delay_minutes"),
            @Result(property = "contactName",column = "contact_name"),
            @Result(property = "imgViewId",column = "img_view_id"),
            @Result(property = "checkStatus",column = "check_status"),
            @Result(property = "delayMinutes",column = "delay_minutes"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "updateTime",column = "update_time"),
            @Result(property = "back",column = "back"),
            @Result(property = "delFlag",column = "del_flag"),
    })
    List<GoodsEntity> getGoodsListBySellerIdAndStatus(@Param("sellerId") Integer sellerId, @Param("checkStatus")Integer checkStatus, @Param("goodsName")String goodsName);
    /**
     * @Author 赵笛
     * @Description TODO 根据id删除竞品
     * @Date 2023/3/30 16:50
     * @Return com.zhuiyun.pm.config.CommonResult
     * @param goodsId
     */
    @Update("update client_goods_info set del_flag = 1 where id = #{goodsId}")
    int deleteGoodsById(@Param("goodsId") Integer goodsId);

    /**
     * @author lyp
     * @description 竞拍中商品，按钮状态
     * @date 2023/4/1 10:39
     * @param: goodsId
     * @return GoodsEntity
     */
    @Select("<script>SELECT transaction_status FROM client_goods_info WHERE id = #{goodsId} LIMIT 1</script>")
    Integer getButton(Integer goodsId);

    /**
     * @author lyp
     * @description 拍卖结束修改商品状态
     * @date 2023/4/1 14:02
     * @param: id
     * @return int
     */
    @Update("<script>UPDATE client_goods_info SET transaction_status = 3 WHERE id = #{goodsId}</script>")
    int updateStatus(@Param("goodsId") Integer goodsId);
}
